package jp.sourceforge.akjrcp.audio;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import jp.sourceforge.akjrcp.snack.PitchToMIDI;

public class Chorus {
	public static Log log=LogFactory.getLog(Chorus.class);
	public static final int[] MAJOR_SCALE={-10,-8,-7,-5,-3,-1,0,2,4,5,7,9,11,12,14,16,17,19,21,23};
	public static int[] getChorusNote(int baseCMajorNote,int choruses[]){
		int ret[]=new int[choruses.length];
		
		int tmpS=PitchToMIDI.noteToScale(baseCMajorNote);
		int index=-1;
		for(int i=6;i<MAJOR_SCALE.length;i++){
			if(tmpS==MAJOR_SCALE[i]){
				index=i;
				break;
			}
		}
		
		if(index==-1){//not much
			for(int i=0;i<choruses.length;i++){
				ret[i]=baseCMajorNote;//no chorus
			}
		}else{
			for(int i=0;i<choruses.length;i++){
				int shiftT=choruses[i]/8;		//8 because start with 1
				int shiftValue=shiftT*12;
				
				int shiftIndex=choruses[i]%8;	//shiftIndex should -1 because 1 is no shift
				if(shiftIndex>0){
					shiftIndex-=1;
				}if(shiftIndex<0){
					shiftIndex+=1;
				}
				log.info("+"+choruses[i]+","+shiftIndex);
				if(shiftIndex!=0){
				
				int modV=MAJOR_SCALE[index+(shiftIndex)]-MAJOR_SCALE[index];
				shiftValue+=modV;	
				log.info("+"+choruses[i]+",shift "+shiftValue);
				
				
				}
				log.info("+"+choruses[i]+",+ octobe "+shiftValue);
				
				ret[i]=baseCMajorNote+shiftValue;
			}
		}
		
		
		return ret;
	}
	
	
}
